﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LightingServer.TCP
{
    public static class Registrar
    {
        private static List<IServerCommand> _commands = new List<IServerCommand>();

        public static int TCPListenPort { get; set; }
        public static int TCPReceiveBufferSize { get; set; }
        public static int TCPSendBufferSize { get; set; }

        public static void Register(IServerCommand command)
        {
            Unregister(command.CommandID);
            _commands.Add(command);
        }

        public static void Unregister(int commandID)
        {
            IServerCommand sourceCommand = GetCommand(commandID);

            if (sourceCommand != null)
            {
                _commands.Remove(sourceCommand);
            }
        }

        internal static IServerCommand GetCommand(int commandID)
        {
            return (from r in _commands
                    where r.CommandID == commandID
                    select r).FirstOrDefault();
        }
    }
}
